# Maintainer: Konstantin Podsvirov <konstantin@podsvirov.pro>

_realname=stork
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.6.0
pkgrel=2
pkgdesc="Impossibly fast web search, made for static sites (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://github.com/jameslittle230/stork"
license=('Apache')
depends=(
  "${MINGW_PACKAGE_PREFIX}-gcc-libs"
  "${MINGW_PACKAGE_PREFIX}-zlib"
)
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-rust"
)
options=('staticlibs' 'strip')
source=("$_realname-$pkgver.tar.gz::$url/archive/v$pkgver.tar.gz")
sha256sums=('cf7f5ed75815bf7e302fd76ec55ac89db2d06a682c5a07b1431d18105b3ada62')

prepare() {
  cd "${srcdir}"
  rm -rf "build-${MSYSTEM}" | true
  cp -r "${_realname}-${pkgver}" "build-${MSYSTEM}"
  cd "${srcdir}/build-${MSYSTEM}"

  ${MINGW_PREFIX}/bin/cargo fetch \
    --locked
}

build() {
  msg "Cargo build for ${MSYSTEM}"
  cd "${srcdir}/build-${MSYSTEM}"

  ${MINGW_PREFIX}/bin/cargo build \
    --release \
    --locked
}

check() {
  cd "${srcdir}/build-${MSYSTEM}"

  ${MINGW_PREFIX}/bin/cargo test \
    --release \
    --locked
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"

  install -Dm755 "target/release/stork.exe" "${pkgdir}${MINGW_PREFIX}/bin/stork.exe"

  install -Dm644 license.txt "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}

